import {configureStore,createSlice,PayloadAction} from '@reduxjs/toolkit'
import { routesConfig, RouteType } from './routes'
const initialState = {
    routes:routesConfig
}

const routesSlice = createSlice({
    name:'router',
    initialState,
    reducers: {
        addRoutes:(state,action: PayloadAction<RouteType[]>) => {
            state.routes = [...state.routes,...action.payload]
        }
    }
})

export const {addRoutes} = routesSlice.actions

const store = configureStore({
    reducer: {
        router: routesSlice.reducer
    }
})

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch

export default store